<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <script src="../js/lib/mdui.min.js"></script>
    <script src="../js/lib/jquery-3.2.1.slim.min.js"></script>
    <script src="../js/lib/holder.min.js"></script>
    <script src="../js/lib/highlight.pack.js"></script>
    <script src="../js/lib/mustache.js"></script>
    <script src="../js/lib/jquery.media.js"></script>
    <script src="../js/docs.js"></script>
    <script src="../js/init.js"></script>
    <script src="../js/listfile.js"></script>
    <link rel="stylesheet" href="../css/mdui.min.css">
    <link rel="stylesheet" href="../css/github-gist.css">
    <link rel="stylesheet" href="../css/railscasts.css">
    <link rel="stylesheet" href="../css/docs.css">
    <link rel="stylesheet" href="../css/mdui.min.css"/>
    <title>欢迎使用STdisk - 集中管理您的所有文件</title>
    <script language="JavaScript">
        function load_public_elements() {
            let div = $("#file-elements");
            let uuid = location.hash.substring(1);
            $.ajax({
                url: api + "/api/getpublicfile",
                dataType: 'json',
                type: 'GET',
                data: {
                    "uuid": uuid
                },
                success: function (data) {
                    let code = data.code;
                    switch (code) {
                        case 0:
                            div.html("");
                            let array = data.items;
                            for (let i = 0; i < array.length; i++) {
                                load_public_item(array[i], div);
                            }
                            break;
                        case -1:
                            mdui.snackbar({
                                message: '未知错误 ' + data.message,
                            });
                            break;
                    }
                }
            });
        }

        // 使用 data 填充模板 append 到 div 下面，同步函数
        // data 一个 LogicFile 元素，div 要显示的div
        function load_public_item(data, div) {
            let template = tem + "/template/file_element.html";
            switch (data.FileType) {
                case "text":
                    data.FileIcon = "text_fields";
                    break;
                case "document":
                    data.FileIcon = "description";
                    break;
                case "audio":
                    data.FileIcon = "audiotrack";
                    break;
                case "video":
                    data.FileIcon = "ondemand_video";
                    break;
                case "image":
                    data.FileIcon = "perm_media";
                    break;
                case "grahpics":
                    data.FileIcon = "grain";
                    break;
                case "software":
                    data.FileIcon = "android";
                    break;
                case "archive":
                    data.FileIcon = "archive";
                    break;
                case "misc":
                    data.FileIcon = "dashboard";
                    break;
                case "mobile":
                    data.FileIcon = "apps";
                    break;
                default:
                    data.FileIcon = "insert_drive_file";
            }
            $.ajax({
                url: template,
                type: "GET",
                dataType: 'html',
                success: function (template) {
                    if (data.FileType === 'dir') {
                        div.append(Mustache.render(template, data));
                    } else {
                        div.prepend(Mustache.render(template, data));
                    }
                    get_public_element(data);
                }
            });
        }

        // 使用 uuid 获取文件信息
        function get_public_element(data) {
            let item = $("#" + data.LogicFileID + "-body"); // 获取内容框
            $.ajax({
                url: tem + "/template/public_sub_element.html",
                // 需要 CreateDate ModifiDate FileSize isPublic LogicFileName
                type: "GET",
                dataType: 'html',
                success: function (template) {
                    data.FileSize = bytesToSize(data.FileSize);
                    item.html(Mustache.render(template, data));
                }
            });
        }
        $(document).ready(function () {
            load_public_elements();
        });
    </script>
</head>

<body class="mdui-appbar-with-toolbar mdui-theme-accent-pink mdui-loaded mdui-theme-primary-blue">
<div class="mdui-appbar mdui-appbar-fixed">
    <div class="mdui-toolbar mdui-color-theme">
        <a href="../index.html" class="mdui-typo-headline">STdisk</a>
        <div class="mdui-toolbar-spacer"></div>
        <span class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white"
              mdui-dialog="{target: '#dialog-docs-theme'}" mdui-tooltip="{content: '设置主题'}"><i
                class="mdui-icon material-icons">color_lens</i></span>
        <a id="logout" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: '登出'}"><i
                class="mdui-icon material-icons">call_missed</i></a>
    </div>
</div>
<div class="mdui-container doc-container mdui-p-t-4">
    <div class="mdui-row">
        <div class="mdui-card">
            <ul id="file-elements" class="mdui-list mdui-p-a-0" mdui-collapse="{accordion: true}">
            </ul>
        </div>
    </div>
</div>
</body>
</html>
